package com.example.lirisheng.springbootfinalexperiment.repositories;


import com.example.lirisheng.springbootfinalexperiment.entity.PersonInformation;
import com.example.lirisheng.springbootfinalexperiment.entity.Users;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;


import java.util.List;

public interface PersonInformationRepository extends CrudRepository<PersonInformation,Integer> {

    public PersonInformation findByResId(Long userId);
    public List<PersonInformation> findByName(String name);

    @Query("select identity from PersonInformation where  house_id = ?1")
    public  String  findByHouseId(String houseId);

    public PersonInformation findByIdentity(String identity);


    @Modifying(clearAutomatically = true)
    @Query("update  PersonInformation set warn= warn+1 where  res_id= ?1 ")
    public void updateAddByResId(Long resId);


    @Modifying(clearAutomatically = true)
    @Query("update PersonInformation set  warn= 0 where  res_id=?1 ")
    public void updateZeroByResId(Long resId);



    @Modifying(clearAutomatically = true)
    @Query("update PersonInformation set name=:name,identity=:identity,house_id=:houseId where id=:id")
    public void updateInfoByResId(@Param("name") String name,
                                  @Param("identity") String identity,
                                  @Param("houseId") String houseId,
                                  @Param("id") Long id);


    @Modifying(clearAutomatically = true)
    @Query("update  PerInfoEntity set entity_times= entity_times+1 where  res_id= ?1 ")
    public void updateEntityTimeByResId(Long resId);


    public List<PersonInformation> findByWarnBetween(Integer frist, Integer last);

    public List<PersonInformation> findByWarnGreaterThanEqual(Integer first);
}
